#include "../../../common/data_mysql.hpp"
#include "../../../odb/chat_session_member.hxx"
#include "chat_session_member-odb.hxx"
#include <gflags/gflags.h>

DEFINE_bool(run_mode, false, "程序的运行模式,false-调试； true-发布；");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");

void append_test(wzl::ChatSessionMemberTable& tb)
{
    wzl::ChatSessionMember csm1("会话ID1","用户ID1");
    tb.append(csm1);
    wzl::ChatSessionMember csm2("会话ID1","用户ID2");
    tb.append(csm2);
    wzl::ChatSessionMember csm3("会话ID2","用户ID3");
    tb.append(csm3);
}

void mutil_append_test(wzl::ChatSessionMemberTable& tb)
{
    wzl::ChatSessionMember csm1("会话ID3","用户ID1");
    wzl::ChatSessionMember csm2("会话ID3","用户ID2");
    wzl::ChatSessionMember csm3("会话ID3","用户ID3");
    std::vector<wzl::ChatSessionMember> list({csm1,csm2,csm3});
    tb.append(list);
}

void remove_test(wzl::ChatSessionMemberTable& tb)
{
    wzl::ChatSessionMember csm3("会话ID2","用户ID3");
    tb.remove(csm3);
}

void ss_members(wzl::ChatSessionMemberTable& tb)
{
    auto res = tb.members("会话ID1");
    for(auto& id : res)
    {   
        std::cout<<id<<" ";
    }
    std::cout<<std::endl;
}

void remove_all_test(wzl::ChatSessionMemberTable& tb)
{
    tb.remove("会话ID3");
}

int main(int argc, char *argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    wzl::init_logger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);
    auto db = wzl::ODBFactory::create("root", "123456", "127.0.0.1", "wzl", "utf8", 0, 1);
    wzl::ChatSessionMemberTable csmt(db);
    // append_test(csmt);
    // mutil_append_test(csmt);
    //remove_test(csmt);
    //ss_members(csmt);
    remove_all_test(csmt);
    return 0;
}